package com.senney.nio;

import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @Author lanmengye@outlook.com
 * @Date 2020/12/29 21:41
 */
public class FileChannel01 {
    public static void main(String[] args) throws Exception {
        String str = "hello, FileChannel...";
        FileOutputStream fileOutputStream = new FileOutputStream("D:\\file01.txt");

        FileChannel fileChannel = fileOutputStream.getChannel();

//        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
//        byteBuffer.put(str.getBytes());
//        byteBuffer.flip();
//        fileChannel.write(byteBuffer);

        fileChannel.write(ByteBuffer.wrap(str.getBytes()));
        fileOutputStream.close();
    }
}
